{% extends "layouts/content.html" %}
{% load django_tables2 %}
{% load utils %}
{% load static %}

{% block content %}

{% if invalid_template %}
<div class="alert alert-danger">
  <strong>Configuration Error: missing or invalid template.</strong>
  <p>Jobs requesting this device type will not be able to start until
     a template is available on the master.</p>
</div>
{% endif %}

<div class="row">
  <div class="col-md-4">
    <dl class="dl-horizontal">
      <dt>Name</dt>
      <dd>{{ dt.name }}
        {% if user.is_superuser %}<a href="{% url 'admin:lava_scheduler_app_devicetype_change' dt %}" title="admin this device-type"><span class="glyphicon glyphicon-wrench"></span></a>{% endif %}
        <a href="#templateModal" data-toggle="modal" data-target="#templateModal" title="show template details"><span class="glyphicon glyphicon-eye-open"></span></a>
      </dd>
      <dt>Description</dt>
      <dd>{{ dt.description|default:"<i>...</i>" }}</dd>
      <dt>Health Checks</dt>
      <dd>{% if dt.disable_health_check %}<span class="text-danger">{{ health_freq }}</span>{% else %}{{ health_freq }}{% endif %} <a href="{% url 'lava.scheduler.device_type_report' dt %}" title="device-type health report"><span class="glyphicon glyphicon-stats"></span></a></dd>
      <dt>Aliases</dt>
      <dd>{{ aliases|default:"<i>...</i>" }}</dd>
    </dl>
  </div>
  <div class="col-md-4">
    <dl class="dl-horizontal">
      <dt>Available</dt>
      <dd><span class="label label-{{ available_devices_label }}">{{ available_devices_count }} / {{ all_devices_count }}</span></dd>
      <dt>Retired</dt>
      <dd>{{ retired_devices_count }}</dd>
      <dt>Queue</dt>
      <dd><span class="label label-{% if queued_jobs_count > available_devices_count %}danger{% elif queued_jobs_count > 0 %}warning{{ queued_jobs_count }}{% else %}default{% endif %}">{{ queued_jobs_count }}</span></dd>
      <dt>Running</dt>
      <dd>{{ running_devices_count }}</dd>
    </dl>
  </div>
  <div class="col-md-4">
    <dl class="dl-horizontal">
      <dt>Architecture</dt>
      <dd>{{ dt.architecture|default:"<i>...</i>" }}{% if dt.bits.width %} ({{ dt.bits.width }} bits){% endif %}</dd>
      <dt>Processor Family</dt>
      <dd>{{ dt.processor|default:"<i>...</i>" }}</dd>
      <dt>CPU model</dt>
      <dd>{{ dt.cpu_model|default:"<i>...</i>" }}</dd>
      <dt>Cores</dt>
      <dd>{{ cores|default:"<i>...</i>" }}</dd>
    </dl>
  </div>
</div>

<div class="modal fade" id="templateModal" tabindex="-1" role="dialog" aria-labelledby="templateModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="templateModalLabel">{{ dt }} template <a href="{% url 'lava_scheduler_download_device_type_yaml' dt %}"><span class="glyphicon glyphicon-download-alt"></span></a></h4>
      </div>
      <div class="modal-body">
      <p>The device-type template needs to be overridden by the device dictionary of each device of this type and is <b>not</b> a valid template for an individual device of this type.</p>
      <h5 class="modal-header">Methods</h5>
      <p>Not all methods may be available on all devices.</p>
      <dl class="dl-horizontal">
        <dt>Deployment</dt>
        <dd>{{ dt|deploy_methods:'deploy'|join:", "|default:"<i>...</i>" }}</dd>
        <dt>Boot</dt>
        <dd>{{ dt|deploy_methods:'boot'|join:", "|default:"<i>...</i>" }}</dd>
      </dl>
      <h5 class="modal-header">Default timeouts</h5>
      <p>Classes named in the default timeouts can be part of the pipeline description which is available from a test job definition, depending on the deployment or boot methods used by that job. </p>
      {% device_type_timeouts dt as timeout_data %}
      <ul>
        {% for timeout_type, action_data in timeout_data.items %}
        <li><i>{{ timeout_type }}</i>
        <dl class="dl-horizontal">
        {% for key, value in action_data.items %}
            <dt>{{ key }}</dt>
            {% if value.seconds %}
            <dd>{{ value.seconds }} seconds</dd>
            {% else %}
            <dd>{{ value.minutes }} minutes</dd>
            {% endif %}
        {% endfor %}
        </dl>
        </li>
        {% endfor %}
      </ul>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<h4 class="modal-header">Devices list</h4>
{% render_table devices_table_no_dt %}

<h4 class="modal-header">Health Job Summary</h4>
{% render_table health_job_summary_table %}

<h4 class="modal-header">Jobs for devices of type {{ dt }}</h4>
{% render_table device_type_jobs_table %}

{% endblock %}

{% block scripts %}
<script type="text/javascript" src="{% static "lava_scheduler_app/js/tables.js" %}"></script>
{% endblock %}
